package helloworld;
/** 
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/


import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JSplitPane;
import javax.swing.JTextField;

import org.objectweb.fractal.api.NoSuchInterfaceException;
import org.objectweb.fractal.api.control.BindingController;

import fr.ema.arch3d.gea.ass.DrawAssImpl;



public class ClientImpl implements BindingController, Runnable {
	
	private Service service;
	public ClientImpl () {
		System.err.println("CLIENT created");
	}
	

	public String[] listFc () {
		return new String[] { "r" };
	}

	public Object lookupFc (final String cItf) {
		if (cItf.equals("r")) {
			return service;
		}
		return null;
	}

	public void bindFc (final String cItf, final Object sItf) {
		if (cItf.equals("r")) {
			service = (Service)sItf;
		}
	}

	public void unbindFc (final String cItf) {
		if (cItf.equals("r")) {
			service = null;
		}
	}
	JTextField JTextField;
	JButton JButton;
	String input;
	JPanel pane;
	JFrame frame;
	public void run() {
		frame=new JFrame();
		JTextField=new JTextField();
		JButton=new JButton("print");
		pane=new JPanel();
		GridBagConstraints gridBagConstraints1 = new GridBagConstraints();
		gridBagConstraints1.fill = GridBagConstraints.VERTICAL;
		gridBagConstraints1.gridy = 1;
		gridBagConstraints1.weightx = 1.0;
		gridBagConstraints1.gridx = 0;
		
		gridBagConstraints1.fill = GridBagConstraints.BOTH;
		GridBagConstraints gridBagConstraints = new GridBagConstraints();
		gridBagConstraints.gridx = 0;
		gridBagConstraints.gridy = 2;
		frame.setSize(300, 200);
		pane.setLayout(new GridBagLayout());
		pane.add(JButton, gridBagConstraints);
		pane.add(JTextField, gridBagConstraints1);
		
		JButton.addActionListener(new ActionListener() {
			
			public void actionPerformed(ActionEvent e) {
				// TODO Auto-generated method stub
				 if (e.getActionCommand().equals("print")) {
				     input=JTextField.getText();
				     
				     service.print(input);
				    }

			}
		});
		
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.add(pane);
		frame.setVisible(true);
	}
}
